package com.company.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.company.model.CompanyInfo;
import com.company.model.CompanyProject;
import com.company.service.CompanyJobService;
import com.company.service.CompanyService;
import com.company.service.ProjectManageService;
import com.system.model.OrgMenu;
import com.system.service.OrgMenuService;

@Controller
public class CompanyController {
	// 页面actionView的地址
	public static final String toCompanyView = "/company";
	//public static final String login = "/loginCheck";

	// 页面路径
	public static final String companyPage = "/company/index";
	
	@Autowired
	OrgMenuService orgMenuService;
	@Autowired
	CompanyService companyService;
	@Autowired
	ProjectManageService projectManageService;
	@Autowired
	CompanyJobService companyJobService;
	
	@RequestMapping(value = toCompanyView, method = RequestMethod.GET)
	public ModelAndView toCompanyView(HttpServletRequest req, HttpServletResponse res) {
		ModelAndView mv = new ModelAndView(companyPage);
		String userId = req.getSession().getAttribute("userId").toString();
		String userName = req.getSession().getAttribute("userName").toString();
		String companyId = req.getSession().getAttribute("companyId").toString();
		List<OrgMenu> menuList = null;
		CompanyInfo companyInfo = null;
		List<CompanyProject> projectList = null;
		List<CompanyProject> endProjectList = null;
		List<Map<String, Object>> companyJobList = null;
		try {
			menuList = orgMenuService.findOrgMenuListByUserId(userId);
			companyInfo = companyService.findCompanyById(companyId);
			projectList = projectManageService.findEndProjectByCompanyId(companyId, "0");
			endProjectList = projectManageService.findEndProjectByCompanyId(companyId, "1");
			companyJobList = companyJobService.findJobByUserIdAndStatus(userId, "0");
		} catch (Exception e) {
			e.printStackTrace();
		}
		mv.addObject("userName", userName);
		mv.addObject("menuList", menuList);
		mv.addObject("companyName", companyInfo.getCompanyName());
		mv.addObject("projectSize", projectList.size());
		mv.addObject("endProjectSize", endProjectList.size());
		mv.addObject("companyJob", companyJobList.size());
		mv.addObject("companyName", companyInfo.getCompanyName());
		
		
		return mv;
	}
}
